package com.example.bms.controller;
import com.example.bms.entity.ApiResult;
import com.example.bms.entity.Replay;
import com.example.bms.serviceimpl.ReplayServiceImpl;
import com.example.bms.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;


/**
 * @apiNote 用于查询和添加回复记录
 * @author 武子砚
 * @email 2681413363@qq.com
 * @since 1.0.0
 */
@RestController
@CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.POST,RequestMethod.PUT,RequestMethod.DELETE})
public class ReplayController {

    @Autowired
    private ReplayServiceImpl replayService;


    /**
     * @apiNote 添加回复信息
     * @param replay 回复对象实体类
     * @author 武子砚
     * @email 2681413363@qq.com
     * @return ApiResult
     * @since 1.0.0
     */
    @PostMapping("/replay")
    public ApiResult add(@RequestBody Replay replay) {
        int data = replayService.add(replay);
        if (data != 0) {
            return ApiResultHandler.buildApiResult(200,"添加成功！",data);
        } else {
            return ApiResultHandler.buildApiResult(400,"添加失败！",null);
        }
    }


    /**
     * @apiNote 根据消息id查询回复记录
     * @param messageId 回复对象实体类
     * @author 武子砚
     * @email 2681413363@qq.com
     * @return ApiResult
     * @since 1.0.0
     */
    @GetMapping("/replay/{messageId}")
    public ApiResult findAllById(@PathVariable("messageId") Integer messageId) {
        System.out.println(messageId);
        System.out.println("1231241242");
        List<Replay> res = replayService.findAllById(messageId);
        return ApiResultHandler.buildApiResult(200,"根据messageId查询",res);
    }
}
